const puppeteer = require('puppeteer');


const Subscription = require('egg').Subscription;

class DownloadCode extends Subscription {
  // 通过 schedule 属性来设置定时任务的执行间隔等配置
  static get schedule() {
    return {
      interval: '2s', // 1 分钟间隔
      type: 'worker', // 指定所有的 worker 都需要执行
    };
  }

  // subscribe 是真正定时任务执行时被运行的函数
  async subscribe() {

    console.log("job");
    
    (async () => {
        const browser = await puppeteer.launch({
          headless: true
        } );
        const page = await browser.newPage();
        await page.goto('http://cmstemp.yaajie.com:8081/index.jsp');
    
        const svgImage = await page.$('#Code');
        await svgImage.screenshot({
          path: '/Users/mbyd/bowerauto/logo-screenshot'+111+'.png',
          omitBackground: true,
        });
        await browser.close();
      })();


  }
}

module.exports = DownloadCode;